var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var PageBase = require('../../common/PageBase.js');
var app = getApp();

Page(common.extendPage(PageBase, {
  data: {
    edit: false,
    flag: false,
    allLoaded: false,
    isLoadMore: false,
    noMore: false,
    dataLoaded: false,
    depotClick: null,
    shopInfo: {},
    evaluateList: [],
    serviceList: [],
    serviceInfo: {},
    services: [],
    species: [],
    storetype: '',
    curSid: '',
    depot: [],
    optionsData: '',
    totalPrice: 0,
    subtotalPrice: '0.00',
    showModal: false,
    drawerUp: false,
    onOff: false,
    tabs: ['简介', '服务', '评价'],
    way: [],
    clothesSku: [],
    shoesSku: [],
    serverTh: ['名称', '单位', '单价', '数量'],
    serverTh1: ['名称', '价格'],
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    currentTab: 0,
    bannerList: [],
    loading: true,
    serviceReady: false,
    specificationsDefalut: {},
    clothesSkuDes:'',
    shoesSkuDes:''
  },
  /**
   * 页面初始化
   */
  onLoad(options) {
    this._options = options;
    this._loadingNum = 2;
    this.setData({
      mid: this._options.mid
    })
    this.getShopInfo();
    this.getBannerList();
  },
  /**
   * 切换tab
   */
  _switchTab(evt) {
    var currentTab = evt.currentTarget.dataset.currentTab;
    this.setData({
      currentTab
    })
    this.flush();
  },
  /**
   * 打开模态层
   */
  _openModal(evt, edit) {
    var sid = evt && evt.currentTarget.dataset.sid;
    if (!edit) {
      this.getServiceInfo(sid);
    }

    this.setData({
      showModal: true,
      edit: false
    })
  },
  /**
   * 关闭模态层
   */
  _closedModal() {
    this.setData({
      showModal: false,
      subtotalPrice: '0.00',
      flag: false,
      depotClick: null
    })
  },
  /**
   * 获取当前选中的种类
   */
  _switchSpecies(evt) {
    var {
      species
    } = this.data;
    this.switchOption(evt, {
      list: species
    }, (list) => {
      this.setData({
        species
      })
    })
  },
  /**
   * 获取当前选中的方式
   */
  _switchWay(evt) {
    var {
      way
    } = this.data;
    this.switchOption(evt, {
      list: way
    }, (list) => {
      var {
        serviceInfo,
        clothesSku,
        storetype,
        shoesSku
      } = this.data;
      var subtotalPrice = 0;
      var clothesSkuDes = '';
      var shoesSkuDes = '';
      if (storetype == 1 || storetype == 8) {
        way.forEach((item, index) => {
          if (item.isSelected) {
            if (item.isSelected) {
              console.log(Object.values(item.skuItem));
              if (item.skuItem['gd_price'] || item.skuItem['gd_price_zk']) {
                clothesSku[2].price = item.skuItem['gd_price_zk'] ? item.skuItem['gd_price_zk'] : item.skuItem['gd_price'];
                clothesSku[2].des = item.skuItem['gd_price_info'];
              } else {
                clothesSku.splice(0, 1);
              }
              if (item.skuItem['jp_price'] || item.skuItem['jp_price_zk']) {
                clothesSku[1].price = item.skuItem['jp_price_zk'] ? item.skuItem['jp_price_zk'] : item.skuItem['jp_price'];
                clothesSku[1].des = item.skuItem['jp_price_info'];
              } else {
                clothesSku.splice(1, 1);
              }
              if (item.skuItem['pt_price'] || item.skuItem['pt_price_zk']) {
                clothesSku[0].price = item.skuItem['pt_price_zk'] ? item.skuItem['pt_price_zk'] : item.skuItem['pt_price'];
                clothesSku[0].des = item.skuItem['pt_price_info'];
              } else {
                clothesSku.splice(2, 1);
              }

              console.log(clothesSku);

              // Object.values(item.skuItem).forEach((val, idx) => {
              //   if (!val) {
              //     clothesSku.splice(index, 1);
              //   } else {
              //     clothesSku[idx].price = val;
              //   }
              // })
            }
          }
        })
        clothesSku.forEach((item, index) => {
          if (item.isSelected) {
            subtotalPrice = parseFloat(item.price);
            clothesSkuDes = item.des;
          }
        })
      }
      if (storetype == 2 || storetype == 9) {
        way.forEach((item, index) => {
          if (item.isSelected) {
            console.log(Object.values(item.skuItem));
            if (item.skuItem['gd_price'] || item.skuItem['gd_price_zk']) {
              shoesSku[2].price = item.skuItem['gd_price_zk'] ? item.skuItem['gd_price_zk'] : item.skuItem['gd_price'];
              shoesSku[2].des = item.skuItem['gd_price_info'];
            } else {
              shoesSku.splice(0, 1);
            }
            if (item.skuItem['jp_price'] || item.skuItem['jp_price_zk']) {
              shoesSku[1].price = item.skuItem['jp_price_zk'] ? item.skuItem['jp_price_zk'] : item.skuItem['jp_price'];
              shoesSku[1].des = item.skuItem['jp_price_info'];
            } else {
              shoesSku.splice(1, 1);
            }
            if (item.skuItem['pt_price'] || item.skuItem['pt_price_zk']) {
              shoesSku[0].price = item.skuItem['pt_price_zk'] ? item.skuItem['pt_price_zk'] : item.skuItem['pt_price'];
              shoesSku[0].des = item.skuItem['pt_price_info'];
            } else {
              shoesSku.splice(2, 1);
            }

            console.log(clothesSku);

            // Object.values(item.skuItem).forEach((val, idx) => {
            //   if (!val) {
            //     clothesSku.splice(index, 1);
            //   } else {
            //     clothesSku[idx].price = val;
            //   }
            // })
          }
        })
        shoesSku.forEach((item, index) => {
          if (item.isSelected) {
            subtotalPrice = parseFloat(item.price);
            shoesSkuDes = item.des;
          }
        })
      }

      if (serviceInfo.services && serviceInfo.services.length > 0) {
        serviceInfo.services.forEach((item, index) => {
          if (item.subtotalPrice) {
            subtotalPrice += parseFloat(item.subtotalPrice);
          }
        })
      }
      if (serviceInfo.services.findIndex((item, index) => {
          return item.num > 0;
        }) == -1) {
        subtotalPrice = 0;
      }

      this.setData({
        way,
        clothesSku,
        shoesSkuDes,
        clothesSkuDes,
        subtotalPrice: subtotalPrice.toFixed(2)
      })
    })
  },
  /**
   * 获取当前选中的衣服的规格
   */
  _switchClothesSku(evt) {
    var {
      clothesSku
    } = this.data;
    this.switchOption(evt, {
      list: clothesSku
    }, (list) => {
      var {
        serviceInfo
      } = this.data;
      var subtotalPrice = 0;
      var clothesSkuDes = '';
      clothesSku.forEach((item, index) => {
        if (item.isSelected) {
          subtotalPrice = parseFloat(item.price);
          clothesSkuDes = item.des;
        }
      })
      if (serviceInfo.services && serviceInfo.services.length > 0) {
        serviceInfo.services.forEach((item, index) => {
          if (item.subtotalPrice) {
            subtotalPrice += parseFloat(item.subtotalPrice);
          }
        })
      }
      if (serviceInfo.services.findIndex((item, index) => {
          return item.num > 0;
        }) == -1) {
        subtotalPrice = 0;
      }
      this.setData({
        clothesSku,
        clothesSkuDes,
        subtotalPrice: subtotalPrice.toFixed(2)
      })
    })
  },
  /**
   * 获取当前选中的鞋子的规格
   */
  _switchShoesSku(evt) {
    var {
      shoesSku
    } = this.data;

    this.switchOption(evt, {
      list: shoesSku
    }, (list) => {

      var {
        serviceInfo
      } = this.data;
      var subtotalPrice = 0;
      var shoesSkuDes = '';
      shoesSku.forEach((item,index)=>{
        if(item.isSelected){
          subtotalPrice = parseFloat(item.price);
          shoesSkuDes = item.des;
        }
      })

      if (serviceInfo.services && serviceInfo.services.length > 0) {
        serviceInfo.services.forEach((item, index) => {
          if (item.subtotalPrice) {
            subtotalPrice += parseFloat(item.subtotalPrice);
          }
        })
      }
      if (serviceInfo.services.findIndex((item, index) => {
        return item.num > 0;
      }) == -1) {
        subtotalPrice = 0;
      }

      this.setData({
        shoesSku,
        shoesSkuDes,
        subtotalPrice: subtotalPrice.toFixed(2)
      })
    })
  },
  /**
   * 服务数量+
   */
  _plus(evt) {
    this.count(evt, 'plus');

  },
  /**
   * 服务数量-
   */
  _minus(evt) {
    this.count(evt, 'minus');
  },
  /**
   * 添加购物车
   */
  _addCart(evt) {
    var {
      storetype,
      curSid,
      serviceInfo,
      species,
      way,
      clothesSku,
      shoesSku,
      flag
    } = this.data;
    var storetype = this.data.storetype;

    var curService = [];
    var paramsUrl = '/public/api/orders/addcarts';
    var paramsDataItem = {};
    var paramsData = {
      uid: wx.getStorageSync('uid'),
      mid: this._options.mid,
      services: {
        item: []
      },
    };

    paramsDataItem.sid = curSid;
    paramsDataItem.title = serviceInfo.title;

    if (storetype == 1 || storetype == 8) {

      species.some((item, index) => {
        if (item.isSelected) {
          paramsDataItem.species = item.name;
        }
      })
      way.some((item, index) => {
        if (item.isSelected) {
          paramsDataItem.ways = item.name;
        }
      })
      clothesSku.some((item, index) => {
        if (item.isSelected) {
          paramsDataItem.specifications = item.name;
        }
      })
    }
    if (storetype == 2 || storetype == 9) {
      species.some((item, index) => {
        if (item.isSelected) {
          paramsDataItem.species = item.name;
        }
      })
      way.some((item, index) => {
        if (item.isSelected) {
          paramsDataItem.ways = item.name;
        }
      })
      shoesSku.some((item, index) => {
        paramsDataItem.specifications = item.name;
      })
    }

    if (serviceInfo.services && serviceInfo.services.length > 0) {
      serviceInfo.services.forEach((item, index) => {
        var curServiceStr = "";
        if (item.num > 0) {
          curServiceStr = item.title + ',' + item.unit + ',' + (item.zk_price ? item.zk_price : item.price) + ',' + item.num;
          curService.push(curServiceStr);
        }
      })
      paramsDataItem["services"] = curService;
    }

    paramsData.services['item'].push(paramsDataItem);
    paramsData.services = JSON.stringify(paramsData.services);

    // if (storetype != 5 && storetype != 6) {
    if (!flag) {
      util.tips('请至少选择一项服务');
      return false;
    }
    // }

    ajax.P({
      url: paramsUrl,
      data: paramsData,
      success: (res) => {
        util.tips("添加成功", () => {
          this._closedModal();
        })
      },
      fail: (res) => {
        console.log(res);
      }
    })
  },
  /**
   * 添加当页底部仓库
   */
  _addDepot(evt) {
    var {
      depot,
      storetype,
      curSid,
      serviceInfo,
      species,
      way,
      clothesSku,
      shoesSku,
      flag,
      depotClick
    } = this.data;
    var storetype = this.data.storetype;
    var totalPrice = 0;
    var depotItem = {};
    var serviceNameArr = [];
    var servicePriceArr = [];

    if (storetype == 3) {
      if (depot && depot.length > 0 && depotClick == null) {
        util.tips('同城物流一次只能添加一个服务');
        return false;
      }
    }
    // if (storetype != 5 && storetype != 6) {
    if (!flag) {
      util.tips('请至少选择一项服务');
      return false;
    }
    // }

    // if (storetype == 5 || storetype == 6) {
    //   if (depot && depot.length > 0) {
    //     if (!depot.some((item, index) => {
    //         if (item.sid == curSid) {
    //           return false;
    //         }
    //       })) {
    //       util.tips('您已经添加过一个同样的服务了');
    //       return false;
    //     }
    //   }
    // }
    if (serviceInfo.services && serviceInfo.services.length > 0) {
      serviceInfo.services.forEach((item, index) => {
        if (item.num > 0) {
          serviceNameArr.push(item.title);
          servicePriceArr.push(item.subtotalPrice);
        }
      })

      depotItem.services = serviceInfo.services;
      depotItem.serviceNameStr = serviceNameArr.join('/');
    }

    depotItem.sid = curSid;
    depotItem.title = serviceInfo.title;


    if (storetype == 1 || storetype == 8) {
      species.some((item, index) => {
        if (item.isSelected) {
          depotItem.species = item.name;
        }
      })
      way.some((item, index) => {
        if (item.isSelected) {
          depotItem.way = item.name;
          /*depotItem.wayPrice = item.price;*/
          /*****/
        }
      })
      clothesSku.some((item, index) => {
        if (item.isSelected) {
          depotItem.specifications = item.name;
          depotItem.specificationsPrice = item.price;
        }
      })
      depotItem.psfee = serviceInfo.psfee;
      /*depotItem.subtotalPrice = parseFloat(depotItem.wayPrice) + parseFloat(depotItem.specificationsPrice);*/
      /******/

      depotItem.subtotalPrice = parseFloat(depotItem.specificationsPrice); /*_______*/

    }
    if (storetype == 2 || storetype == 9) {
      species.some((item, index) => {
        if (item.isSelected) {
          depotItem.species = item.name;
        }
      })
      way.some((item, index) => {
        if (item.isSelected) {
          depotItem.way = item.name;
          /*depotItem.wayPrice = item.price;*/
          /*****/
        }
      })
      shoesSku.some((item, index) => {
        if (item.isSelected) {
          depotItem.specifications = item.name;
          depotItem.specificationsPrice = item.price;
        }
      })
      depotItem.psfee = serviceInfo.psfee;
      depotItem.subtotalPrice = parseFloat(depotItem.specificationsPrice);
    }
    if (storetype == 3) {
      depotItem.distance = serviceInfo.distance;
      depotItem.handling = serviceInfo.handling;
      depotItem.jiashou = serviceInfo.jiashou;
    }
    if (storetype == 5 || storetype == 6) {
      depotItem.subtotalPrice = parseFloat(serviceInfo.plat_fee);
    }
    if (storetype == 7) {
      depotItem.materials = parseFloat(serviceInfo.materials);
      depotItem.artificial = parseFloat(serviceInfo.artificial);
    }

    depotItem.subtotalPrice = depotItem.subtotalPrice || 0;

    servicePriceArr.forEach((item, index) => {
      depotItem.subtotalPrice += item;
    })
    depotItem.subtotalPrice = parseFloat(depotItem.subtotalPrice).toFixed(2)
    if (depotClick != null) {
      depot.some((item, index) => {
        if (depotClick == index) {
          depot.splice(index, 1, depotItem);
        }
      })
    } else {
      depot.push(depotItem);
    }

    // if (storetype != 5 && storetype != 6) {
    depot.forEach((item, index) => {
      totalPrice = parseFloat(totalPrice) + parseFloat(item.subtotalPrice);
    })

    this.setData({
      depot,
      optionsData: JSON.stringify(depot),
      totalPrice: parseFloat(totalPrice).toFixed(2)
    })

    this._closedModal();
  },
  _resetModalData(evt) {
    var {
      sid,
      currentIndex
    } = evt.currentTarget.dataset;

    var {
      depot,
      serviceInfo,
      species,
      way,
      clothesSku,
      shoesSku,
      storetype
    } = this.data;

    var subtotalPrice = 0;
    var serviceTotalPrice = 0;

    this._flag = true;
    depot.some((item, index) => {
      if (currentIndex == index) {
        if (storetype == 1 || storetype == 8) {
          species.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.species) {
              val.isSelected = true;
            }
          })
          way.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.way) {
              val.isSelected = true;
              /*subtotalPrice += parseFloat(val.price);*/
              /*******/
            }
          })
          clothesSku.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.specifications) {
              val.isSelected = true;
              subtotalPrice += parseFloat(val.price);
            }
          })
        }
        if (storetype == 2 || storetype == 9) {
          species.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.species) {
              val.isSelected = true;
            }
          })
          way.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.way) {
              val.isSelected = true;
              /*subtotalPrice += parseFloat(val.price);*/
              /*******/
            }
          })
          shoesSku.some((val, idx) => {
            val.isSelected = false;
            if (val.name == item.specifications) {
              val.isSelected = true;
              subtotalPrice += parseFloat(val.price);
            }
          })
        }
        if (storetype == 5 || storetype == 6) {
          subtotalPrice = parseFloat(serviceInfo.plat_fee);
        }
        serviceInfo.services = item.services;
        serviceInfo.title = item.title;
      }
    })
    if (serviceInfo.services && serviceInfo.services.length > 0) {
      serviceInfo.services.forEach((item, index) => {
        item.subtotalPrice = item.num * (item.zk_price ? item.zk_price : item.price);
        if (item.subtotalPrice) {
          serviceTotalPrice += parseFloat(item.subtotalPrice);
        }
      })
      if (serviceInfo.services.findIndex((item, index) => {
          return item.num > 0;
        }) == -1) {
        subtotalPrice = 0;
        this._flag = false;
      }
    }

    subtotalPrice += serviceTotalPrice;

    this.setData({
      species,
      way,
      clothesSku,
      shoesSku,
      curSid: sid,
      serviceInfo,
      edit: true,
      flag: this._flag,
      depotClick: currentIndex,
      subtotalPrice: subtotalPrice.toFixed(2)
    })
    this.powerDrawer(evt);
    this._openModal(null, this.data.edit);
  },
  /**
   * 下拉加载
   */
  onReachBottom() {
    this.loadMore()
  },
  _showTips() {
    util.tips('请选择服务项目');
  },
  /**
   *刷新
   */
  flush() {
    var currentTab = this.data.currentTab;

    this.setData({
      page: 1,
      allLoaded: false,
      noMore: false,
      isLoadMore: false
    });

    switch (currentTab) {
      case 1:
        this.getServiceList(true, () => {
          wx.stopPullDownRefresh();
        });
        break;
      case 2:
        this.getEvaluateList(true, () => {
          wx.stopPullDownRefresh();
        });
        break;
    }
  },
  /**
   * 获取店铺详情
   */
  getShopInfo() {
    var paramsUrl = '/public/api/shops/shopDetail';
    var parmasData = {
      mid: this._options.mid
    }
    ajax.P({
      url: paramsUrl,
      data: parmasData,
      success: (res, isLoadcb) => {
        this._loadingNum--;
        if (this._loadingNum == 0) {
          this._loading = false;
        }
        this.setData({
          shopInfo: res.data,
          storetype: res.data.storetype,
          loading: this._loading
        })
        isLoadcb && isLoadcb();
      },
      fail: (res) => {}
    })
  },
  /**
   * 切换底部抽屉
   */
  powerDrawer: function(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    var depot = this.data.depot;

    if (!(depot && depot.length > 0)) {
      return false;
    }
    if (currentStatu == 'open' && this.data.onOff) {
      return false;
    }
    this.util(currentStatu);
  },
  util: function(currentStatu, cb) {
    /* 动画部分 */
    // 第1步：创建动画实例 
    var animation = wx.createAnimation({
      duration: 200, //动画时长
      timingFunction: "linear", //线性
      delay: 0 //0则不延迟
    });


    // 第2步：这个动画实例赋给当前的动画实例
    this.animation = animation;

    // 第3步：执行第一组动画：Y轴偏移240px后(盒子高度是240px)，停
    animation.translateY(240).step();

    // 第4步：导出动画对象赋给数据对象储存
    this.setData({
      animationData: animation.export()
    })


    // 第5步：设置定时器到指定时候后，执行第二组动画
    setTimeout(function() {
      // 执行第二组动画：Y轴不偏移，停
      animation.translateY(0).step()
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象
      this.setData({
        animationData: animation
      })

      //关闭抽屉
      if (currentStatu == "close") {
        this.setData({
          drawerUp: false,
          onOff: false
        });
      }
    }.bind(this), 200)

    // 显示抽屉
    if (currentStatu == "open") {
      this.setData({
        drawerUp: true,
        onOff: true
      });
    }
  },
  /**
   * 获取评价列表
   */
  getEvaluateList(isFlush, cb) {
    var evaluateList = this.data.evaluateList;
    var page = this.data.page;
    var paramsUrl = '/public/api/shops/startlist';
    var paramsData = {
      mid: this._options.mid,
      page: page || 1,
      num: 10
    }
    ajax.P({
      url: paramsUrl,
      data: paramsData,
      success: (res, isLoadcb) => {
        var listData = res.data || [];
        var allLoaded = false;
        var noMore = false;

        if (listData.length == 0) {
          allLoaded = true;
          noMore = true;
        }
        if (isFlush) {
          evaluateList = listData;
        } else {
          evaluateList = evaluateList.concat(listData);
        }
        this.setData({
          evaluateList,
          page: ++page,
          allLoaded,
          noMore
        })
        isLoadcb && isLoadcb();
        cb && cb();
      },
      fail: (res) => {},
      unneedLoad: true
    })
  },
  /**
   * 获取服务列表
   */
  getServiceList(isFlush, cb) {
    var serviceList = this.data.serviceList;
    var page = this.data.page;
    var paramsUrl = '/public/api/shops/servicelist';
    var paramsData = {
      mid: this._options.mid,
      page: page || 1,
      num: 10
    }
    ajax.P({
      url: paramsUrl,
      data: paramsData,
      success: (res, isLoadcb) => {
        var listData = res.data || [];
        var allLoaded = false;
        var noMore = false;

        if (listData.length == 0) {
          allLoaded = true;
          noMore = true;
        }
        if (isFlush) {
          serviceList = listData;
        } else {
          serviceList = serviceList.concat(listData);
        }
        this.setData({
          serviceList,
          page: ++page,
          allLoaded,
          noMore
        })
        isLoadcb && isLoadcb();
        cb && cb();
      },
      fail: (res) => {},
      unneedLoad: true
    })
  },
  /**
   * 获取店铺服务详情
   */
  getServiceInfo(sid) {
    var {
      storetype,
      clothesSku,
      shoesSku,
      species
    } = this.data;

    var way = [{
      name: '干洗',
      isSelected: true
    }, {
      name: '水洗',
      isSelected: false
    }]

    var clothesSku = [{
      name: '普通洗衣',
      isSelected: true
    }, {
      name: '精品洗衣',
      isSelected: false
    }, {
      name: '高档洗衣',
      isSelected: false
    }];

    var shoesSku = [{
        name: '普通洗鞋',
        isSelected: true
      },
      {
        name: '精品洗鞋',
        isSelected: false
      },
      {
        name: '高档洗鞋',
        isSelected: false
      }
    ]

    var paramsUrl = '/public/api/shops/serviceDetail';
    var paramsData = {
      sid
    }
    this.setData({
      serviceReady: false
    })
    ajax.P({
      url: paramsUrl,
      data: paramsData,
      success: (res, isLoadcb) => {
        var serviceInfo = res.data;
        var species = [];
        if (storetype == 1 || storetype == 8) {
          serviceInfo.species.forEach((item, index) => {
            var speciesItem = {};
            speciesItem.name = item;
            speciesItem.isSelected = false;
            species.push(speciesItem);
          })
          species[0].isSelected = true;

          /**
           * 5月13日改
           */
          way[0].skuItem = serviceInfo.specifications.dry;
          way[1].skuItem = serviceInfo.specifications.water;
          console.log(way, '~~~~~~~~~~~~~~~~~~~');
          /*end*/

          way.forEach((item, index) => {
            if (item.isSelected) {
              console.log(Object.values(item.skuItem));
              if (item.skuItem['gd_price'] || item.skuItem['gd_price_zk']){
                clothesSku[2].price = item.skuItem['gd_price_zk'] ? item.skuItem['gd_price_zk'] : item.skuItem['gd_price'];
                clothesSku[2].des = item.skuItem['gd_price_info'];
              }else{
                clothesSku.splice(0, 1);
              }
              if (item.skuItem['jp_price'] || item.skuItem['jp_price_zk']){
                clothesSku[1].price = item.skuItem['jp_price_zk'] ? item.skuItem['jp_price_zk'] : item.skuItem['jp_price'];
                clothesSku[1].des = item.skuItem['jp_price_info'];
              }else{
                clothesSku.splice(1, 1);
              }
              if (item.skuItem['pt_price'] || item.skuItem['pt_price_zk']){
                clothesSku[0].price = item.skuItem['pt_price_zk'] ? item.skuItem['pt_price_zk'] : item.skuItem['pt_price'];
                clothesSku[0].des = item.skuItem['pt_price_info'];
              }else{
                clothesSku.splice(2, 1);
              }

              console.log(clothesSku);
              
              // Object.values(item.skuItem).forEach((val, idx) => {
              //   if (!val) {
              //     clothesSku.splice(index, 1);
              //   } else {
              //     clothesSku[idx].price = val;
              //   }
              // })
            }
          })
        }

        if (storetype == 2 || storetype == 9) {

          serviceInfo.species.forEach((item, index) => {
            var speciesItem = {};
            speciesItem.name = item;
            speciesItem.isSelected = false;
            species.push(speciesItem);
          })
          species[0].isSelected = true;

          /**
           * 5月13日改
           */
          way[0].skuItem = serviceInfo.specifications.dry;
          way[1].skuItem = serviceInfo.specifications.water;
          console.log(way, '~~~~~~~~~~~~~~~~~~~');
          /*end*/

          way.forEach((item, index) => {
            if (item.isSelected) {
              if (item.isSelected) {
                console.log(Object.values(item.skuItem));
                if (item.skuItem['gd_price'] || item.skuItem['gd_price_zk']) {
                  shoesSku[2].price = item.skuItem['gd_price_zk'] ? item.skuItem['gd_price_zk'] : item.skuItem['gd_price'];
                  shoesSku[2].des = item.skuItem['gd_price_info'];
                } else {
                  shoesSku.splice(0, 1);
                }
                if (item.skuItem['jp_price'] || item.skuItem['jp_price_zk']) {
                  shoesSku[1].price = item.skuItem['jp_price_zk'] ? item.skuItem['jp_price_zk'] : item.skuItem['jp_price'];
                  shoesSku[1].des = item.skuItem['jp_price_info'];
                } else {
                  shoesSku.splice(1, 1);
                }
                if (item.skuItem['pt_price'] || item.skuItem['pt_price_zk']) {
                  shoesSku[0].price = item.skuItem['pt_price_zk'] ? item.skuItem['pt_price_zk'] : item.skuItem['pt_price'];
                  shoesSku[0].des = item.skuItem['pt_price_info'];
                } else {
                  shoesSku.splice(2, 1);
                }

                console.log(clothesSku);

                // Object.values(item.skuItem).forEach((val, idx) => {
                //   if (!val) {
                //     clothesSku.splice(index, 1);
                //   } else {
                //     clothesSku[idx].price = val;
                //   }
                // })
              }
              // Object.values(item.skuItem).forEach((val, idx) => {
              //   if (!val) {
              //     shoesSku.splice(index, 1);
              //   } else {
              //     shoesSku[idx].price = val;
              //   }
              // })
            }
          })
        }

        if (storetype == 5 || storetype == 6) {
          this._subtotalPrice = parseFloat(serviceInfo.plat_fee).toFixed(2);
        }

        if (serviceInfo.services && serviceInfo.services.length > 0) {
          serviceInfo.services.forEach((item, index) => {
            item.num = 0;
          })
        }
        console.log(clothesSku);
        this.setData({
          serviceInfo,
          way,
          clothesSku,
          shoesSku,
          species,
          curSid: sid,
          subtotalPrice: this._subtotalPrice || '0.00',
          serviceReady: true,
          clothesSkuDes: clothesSku[0].des,
          shoesSkuDes: shoesSku[0].des 
        })
        isLoadcb && isLoadcb();
      },
      fail: (res) => {}
    })
  },
  /**
   * 加载更多
   */
  loadMore() {
    var {
      allLoaded,
      currentTab
    } = this.data;

    if (allLoaded) {
      return;
    } else {
      this.setData({
        isLoadMore: true
      })
      switch (currentTab) {
        case 1:
          this.getServiceList(false, () => {
            this.setData({
              dataLoaded: true,
              isLoadMore: false
            })
          });
          break;
        case 2:
          this.getEvaluateList(false, () => {
            this.setData({
              dataLoaded: true,
              isLoadMore: false
            })
          });
          break;
      }
    }
  },
  /**
   * 种类、方式、规格切换
   */
  switchOption(evt, params, cb) {
    var optionId = evt.currentTarget.dataset.optionId;
    var {
      list
    } = params;
    list.forEach((item, index) => {
      item.isSelected = false;
      if (optionId == index) {
        item.isSelected = true;
      }
    })
    cb && cb(list);
  },
  /**
   * 计算服务数量
   */
  count(evt, params) {
    var {
      serviceId
    } = evt.currentTarget.dataset;

    this._flag = true;

    var {
      serviceInfo,
      way,
      clothesSku,
      shoesSku,
      storetype
    } = this.data;

    var subtotalPrice = 0;
    var serviceTotalPrice = 0;

    if (storetype == 1 || storetype == 8) {

      clothesSku.some((item, index) => {
        if (item.isSelected) {
          subtotalPrice += parseFloat(item.price);
        }
      })
    }

    if (storetype == 2 || storetype == 9) {
      shoesSku.some((item, index) => {
        if (item.isSelected) {
          subtotalPrice += parseFloat(item.price);
        }
      })
    }

    if (serviceInfo.services && serviceInfo.services.length > 0) {
      serviceInfo.services.forEach((item, index) => {
        if (serviceId == index) {
          params == 'plus' ? item.num++ : item.num--;
          item.subtotalPrice = item.num * (item.zk_price ? item.zk_price : item.price);
        }
        if (item.subtotalPrice) {
          serviceTotalPrice += parseFloat(item.subtotalPrice);
        }
      })
      if (serviceInfo.services.findIndex((item, index) => {
          return item.num > 0;
        }) == -1) {
        subtotalPrice = 0;
        this._flag = false;
      }
    }

    subtotalPrice += serviceTotalPrice;

    if (storetype == 5 || storetype == 6) {
      subtotalPrice += parseFloat(serviceInfo.plat_fee);
    }
    console.log(serviceInfo, '@@@@@@');

    this.setData({
      serviceInfo,
      subtotalPrice: subtotalPrice.toFixed(2),
      flag: this._flag
    })
  },
  getBannerList() {
    var paramsUrl = '/public/api/index/banner';
    ajax.P({
      url: paramsUrl,
      data: {},
      success: (res, isLoadcb) => {
        var list = res.data;
        this._loadingNum--;
        if (this._loadingNum == 0) {
          this._loading = false;
        }
        this.setData({
          bannerList: list,
          loading: this._loading
        })
        isLoadcb && isLoadcb();
      },
      fail: (res) => {}
    })
  },
}));